set more off

use dataset, clear

*** covariates ***

local X1 totalrevownsourcespcp pcttotaltax pcttotalig
local X2 lpopulation popdensity incomepcp pctba pct65plus 
local X3 crimepcp totalpolicepcp dem ngovspcp netmigration H pcthisp herf pctforeign

local X `X1' `X2' `X3'

replace pctblackgov = log(pctblackgov + 1)

*** rescale ***

foreach x in `X' pctblack pctblackgov {
	su `x'
	replace `x' = (`x' - r(min)) / (r(max) - r(min))
	drop if mi(`x')
}

*** interactions ***

gen pctblackXpctblackgov = pctblack*pctblackgov
gen pctblackXanyblackgov = pctblack*anyblackgov

label variable pctblack "Percent black population"
label variable pctblackgov "Percent black council"
label variable anyblackgov "Any black council"
label variable pctblackXpctblackgov "Black pop X black council"
label variable pctblackXanyblackgov "Black pop X any black council"

*** regressions ***

eststo clear

eststo: reg lfinesandforfeitspcp pctblack anyblackgov, robust
eststo: reg lfinesandforfeitspcp pctblack anyblackgov `X', robust
estadd local Controls = "\checkmark"
eststo: reg lfinesandforfeitspcp pctblack anyblackgov pctblackXanyblackgov, robust
eststo: reg lfinesandforfeitspcp pctblack anyblackgov pctblackXanyblackgov `X', robust
estadd local Controls = "\checkmark"
eststo: reg lfinesandforfeitspcp pctblack pctblackgov pctblackXpctblackgov, robust
eststo: reg lfinesandforfeitspcp pctblack pctblackgov pctblackXpctblackgov `X', robust
estadd local Controls = "\checkmark"

#delimit;

esttab 
	using "tableA4.tex"
	,
		replace 
		label
		star(* .05 ** .01 *** .001)
		booktabs
		cells(b(fmt(2) star) se(par))
		collabels(none)
		nomtitles
		order(pctblack anyblackgov pctblackXanyblackgov pctblackgov pctblackXpctblackgov )
		stats(
			N r2
			,
				label("Sample size" "R-squared")
				fmt(%20.0fc %20.02fc)
		)			width(\textwidth)
		
		;
#delimit cr

esttab, keep(pctblack* pctblack) stats(mydiff1 mydiff0 mydiff) se compress star(+ .1 * .05 ** .01 *** .001)
